package com.pb.infra.oth.util;

import lombok.extern.slf4j.Slf4j;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

/**
 * 随机数通用类
 *
 * @Author:liudebao
 * @Date: 2020/6/22
 */
@Slf4j
public class RandomUtil {
    private RandomUtil() {
        throw new IllegalStateException("Utility class");
    }

    /**
     * 获取随机数
     *
     * @return
     */
    public static String getRandom() {
        try {
            return String.format("%.5f", SecureRandom.getInstance("SHA1PRNG").nextFloat()).substring(2);
        } catch (NoSuchAlgorithmException e) {
            log.error("failed to getRandom.", e);
        }
        return null;
    }
}
